import java.util.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @ProjectName leetcode
 * @Author Ding
 * @CreateTime 2022/9/3 23:09 星期六
 */
public class Main5 {
    public static void main(String[] args) {
        String s = "abaccb";
        int[] arr = new int[]{1, 3, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        System.err.println(checkDistances(s, arr));
    }

    public static boolean checkDistances(String s, int[] distance) {
        Map<Integer, List<Integer>> map = new HashMap<>();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            List<Integer> set = map.get(chars[i] - 'a');
            if (set == null) {
                set = new ArrayList<Integer>();
            }
            set.add(i);

            map.put(chars[i] - 'a', set);
        }
        for (int i = 0; i < distance.length; i++) {
            if (map.containsKey(i)) {
                List<Integer> set = map.get(i);

                if (distance[i] != set.get(1) - set.get(0) - 1) {
                    return false;
                }
            }
        }
        return true;
    }
}
